<template>
  <div style="padding:50px 0;width:45%">
    <el-form ref="form" :model="form" :rules="rule" label-width="260px">
      <el-form-item label="手 机：" prop="mobile">
        <el-input v-model="form.mobile" />
      </el-form-item>
      <el-form-item label="入职时间：" prop="timeOfEntry">
        <el-date-picker v-model="form.timeOfEntry" type="date" placeholder="选择日期" style="width: 100%;" />
      </el-form-item>
      <el-form-item label="用户头像：">
        <!-- 头像 -->
        <!-- <img :src="form.staffPhoto" alt=""> -->
        <upload-img v-model="form.staffPhoto" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onUpdate">保存更新</el-button>
        <el-button @click="$router.back()">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { getUserDetailById, updateDetailById } from '@/api/user'
import UploadImg from '@/components/UploadImg'
export default {
  name: '',
  components: {
    UploadImg
  },
  data() {
    return {
      form: {
        userId: this.$route.query.id,
        mobile: '',
        timeOfEntry: '',
        staffPhoto: ''
      },
      rule: {
        mobile: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
        timeOfEntry: [{ required: true, message: '请选择日期', trigger: 'change' }]
      }
    }
  },
  computed: {
  },
  created() {
    this.initUserInfo()
  },
  methods: {
    async initUserInfo() {
      const res = await getUserDetailById(this.$route.query.id)
      this.form = res.data
    },
    onUpdate() {
      this.$refs.form.validate(async valid => {
        if (!valid) return
        try {
          await updateDetailById(this.form)
          this.$message.success('保存用户基本信息成功')
        } catch (err) {
          console.log(err)
        }
      })
    }
  }
}
</script>
<style lang='less'  scoped>

</style>
